<?php
/**
 * Created by PhpStorm.
 * User: zhenghao
 * Date: 2015/6/17
 * Time: 17:34
 */

require_once __DIR__."/../lib/SmsClient.php";

class SmsBO {


    //发送短信验证码
    static function sendCode($phone){

        //检查手机号码格式
        if(!check_phone_formate($phone)) throw new Exception("手机号码格式不正确");

        //获取6位随机数字
        $s_code=rand(100000,999999);

        $sms_client=new SmsClient();

        $content="【有色网】您的注册验证码是：".$s_code;

        $statusCode=$sms_client->sendSms(array($phone),$content);

        if(!$statusCode==0) throw new Exception("验证码发送失败.错误编码：".$statusCode);

        return $s_code;
    }

}